package esb.chapter5.transformation.camel;

import javax.xml.transform.dom.DOMSource;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.w3c.dom.Node;

public class ConvertProcessor implements Processor {
	
	public void process(Exchange exchange) throws Exception {
		DOMSource payload = (DOMSource) exchange.getIn().getBody();
		System.out.println("root element " + payload.getNode().getNodeName());
		Node resultNode = payload.getNode().getFirstChild();
		System.out.println("resultNode " + resultNode.getNodeName());
		String weatherContent = resultNode.getTextContent();
		System.out.println("weatherContent " + weatherContent);
		Message responseMessage = exchange.getOut();
		responseMessage.setBody(new StringSource(weatherContent));
    }

}
